package com.ljcalc.business.components;

import java.util.List;

import com.ljcalc.business.components.requests.HistoryResultRequest;
import com.ljcalc.business.components.requests.SPTTHistoryResultRequest;

public class SPTTResultHistories extends ResultHistory {

	private static final String DEFAULT_PROPERTY_FILE_NAME = "sptt.result.histories";
	private static SPTTResultHistories instance;
	
	protected SPTTResultHistories(String defaultFileName, String fn) {
		super(defaultFileName, fn);
		// TODO Auto-generated constructor stub
	}
	
	private SPTTResultHistories(String fn){
		super(DEFAULT_PROPERTY_FILE_NAME, fn);
	}
	
	public static SPTTResultHistories getInstance(){
		if(instance==null){
			instance = new SPTTResultHistories(null);
			HISTORY_TYPE = ResultHistory.SPTT_TYPE;
		}
		return instance;
	}
	
    public HistoryResultRequest getResultInRequest(String key){
    	HistoryResultRequest hrr =  super.getResultInRequest(key);
		return new SPTTHistoryResultRequest(hrr.getRound());
    }
    
    public boolean setResults(int type, int year, int round, List<Combination> results){
    	
    	String key = generateKey(type,year,round);
    	if(results==null){
    		System.out.println(key + " has problem");
    		return false;
    	}else{
    		properties.setProperty(key, results.toString());
    		System.out.println(key + " is set as property");
    		 this.latestRound = round;
    		return true;
    	}
    }
}
